/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package co.edu.unitecnologica.modelo;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author osalcedo
 */
@Entity
@Table(name = "roles")
@NamedQueries({@NamedQuery(name = "Roles.findAll", query = "SELECT r FROM Roles r"), @NamedQuery(name = "Roles.findByCod", query = "SELECT r FROM Roles r WHERE r.cod = :cod"), @NamedQuery(name = "Roles.findByDescripcion", query = "SELECT r FROM Roles r WHERE r.descripcion = :descripcion")})
public class Roles implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "cod")
    private Integer cod;
    @Basic(optional = false)
    @Column(name = "descripcion")
    private String descripcion;
    @ManyToMany(mappedBy = "rolesCollection")
    private Collection<Usuarios> usuariosCollection;
    @JoinTable(name = "roles_objetos", joinColumns = {@JoinColumn(name = "cod_rol", referencedColumnName = "cod")}, inverseJoinColumns = {@JoinColumn(name = "cod_objeto", referencedColumnName = "cod")})
    @ManyToMany
    private Collection<Objetos> objetosCollection;

    public Roles() {
    }

    public Roles(Integer cod) {
        this.cod = cod;
    }

    public Roles(Integer cod, String descripcion) {
        this.cod = cod;
        this.descripcion = descripcion;
    }

    public Integer getCod() {
        return cod;
    }

    public void setCod(Integer cod) {
        this.cod = cod;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Collection<Usuarios> getUsuariosCollection() {
        return usuariosCollection;
    }

    public void setUsuariosCollection(Collection<Usuarios> usuariosCollection) {
        this.usuariosCollection = usuariosCollection;
    }

    public Collection<Objetos> getObjetosCollection() {
        return objetosCollection;
    }

    public void setObjetosCollection(Collection<Objetos> objetosCollection) {
        this.objetosCollection = objetosCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cod != null ? cod.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Roles)) {
            return false;
        }
        Roles other = (Roles) object;
        if ((this.cod == null && other.cod != null) || (this.cod != null && !this.cod.equals(other.cod))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.edu.unitecnologica.modelo.Roles[cod=" + cod + "]";
    }

}
